use "/Users/kerem/Library/CloudStorage/Dropbox/papers/1-currently working/political regime change and culture/kerem new work/working data.dta"

*change four countries where regime change happened after the first wave:
replace regimes=3 if COUNTRY_ALPHA=="TUR" & S002VS==6
replace regimes=3 if COUNTRY_ALPHA=="THA" & S002VS==6
replace regimes=3 if COUNTRY_ALPHA=="PHL" & S002VS==6
replace regimes=3 if COUNTRY_ALPHA=="IND" & S002VS==6
replace regime="democracy" if COUNTRY_ALPHA=="TUR" & S002VS==6
replace regime="democracy" if COUNTRY_ALPHA=="THA" & S002VS==6
replace regime="democracy" if COUNTRY_ALPHA=="PHL" & S002VS==6
replace regime="democracy" if COUNTRY_ALPHA=="IND" & S002VS==6

*we imputed gini by going back 5 years in data

mixed ratio i.partisaninpower##i.regimes educ2 i.sex age income i.S002VS total_confidence interpersonal_trust ideology || S003: gini gdp growth
gen effective_sample=e(sample)

*country and regime list years, appendix table:
preserve
encode regime, gen(reggg)
collapse (mean) reggg if effective_sample==1, by(COUNTRY_ALPHA COW_NUM COW_ALPHA S002VS S020 S002VS)
reshape wide S020 reggg, i(COUNTRY_ALPHA COW_NUM COW_ALPHA)  j(S002VS)
tostring reggg6, replace
decode COW_NUM, gen(country)
drop COUNTRY_ALPHA COW_NUM COW_ALPHA
rename S0206 year_1
rename S0207 year_2
rename reggg6 regime_1
rename reggg7 regime_2
tostring regime_2, replace
replace regime_1="Demoratic" if regime_1=="3"
replace regime_1="Autocratic" if regime_1=="1"
replace regime_1="Backsliding" if regime_1=="2"

replace regime_2="Demoratic" if regime_2=="3"
replace regime_2="Autocratic" if regime_2=="1"
replace regime_2="Backsliding" if regime_2=="2"
edit
restore

mixed ratio i.partisaninpower##ib3.regimes || S003: if effective_sample==1
eststo m1

mixed ratio i.partisaninpower##ib3.regimes educ2 i.sex age income i.S002VS || S003: if effective_sample==1
eststo m2

mixed ratio i.partisaninpower##ib3.regimes educ2 i.sex age income i.S002VS total_confidence interpersonal_trust ideology || S003: if effective_sample==1
eststo m3

mixed ratio i.partisaninpower##ib3.regimes educ2 i.sex age income i.S002VS total_confidence interpersonal_trust ideology || S003: gini gdp growth if effective_sample==1
eststo m4


esttab * using table1.rtf, cells(b(star fmt(%9.3f)) se(par))      stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared))       legend label collabels(none) varlabels(_cons Constant) transform(ln*: (exp(@)^2) d(2*exp(@)^2)) replace



*appendix table 1 country level:
preserve

collapse (mean) ratio gini gdp growth regimes, by(S002VS S003) 

reg ratio gini gdp growth i.S002VS i.regimes 
eststo appendix1

esttab appendix1 using appendix1.rtf, cells(b(star fmt(%9.3f)) se(par))      stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared) legend label collabels(none) varlabels(_cons Constant)  replace


*robustness check did the effect become more prominent across backsliding countries over time as they backslide?
gen robustness=1 if COUNTRY_ALPHA=="TUR"
replace robustness=1 if COUNTRY_ALPHA=="THA"
replace robustness=1 if COUNTRY_ALPHA=="PHL"
replace robustness=1 if COUNTRY_ALPHA=="IND"

reg ratio i.partisaninpower##i.S002VS educ2 i.sex age income  total_confidence interpersonal_trust ideology if robustness==1
eststo appm2
margins partisaninpower#S002VS
marginsplot, xdimension(S002VS)

esttab appm2 using table3.rtf, cells(b(star fmt(%9.3f)) se(par))      stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared))       legend label collabels(none) varlabels(_cons Constant) transform(ln*: exp(@) exp(@)) replace
